import {
  Column,
  CreateDateColumn,
  Entity,
  ManyToOne,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';
import { User } from '../../user/entities/user.entity';
import { Goods } from '../../goods/entities/goods.entity';
import { Address } from '../../address/entities/address.entity';

@Entity()
export class Order {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ length: 20, unique: true })
  orderNo: string;

  @Column({ type: 'decimal', precision: 10, scale: 2 })
  amount: number;

  @Column({ default: 1 })
  status: number; // 1: 待付款, 2: 待发货, 3: 待收货, 4: 已完成, 5: 已取消

  @Column({ nullable: true })
  payTime: Date;

  @Column({ nullable: true })
  shipTime: Date;

  @Column({ nullable: true })
  completeTime: Date;

  @ManyToOne(() => User, (user) => user.buyOrders)
  buyer: User;

  @ManyToOne(() => User, (user) => user.sellOrders)
  seller: User;

  @ManyToOne(() => Goods, (goods) => goods.orders)
  goods: Goods;

  @ManyToOne(() => Address)
  address: Address;

  @CreateDateColumn()
  createTime: Date;

  @UpdateDateColumn()
  updateTime: Date;
}
